import 'dart:ui';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class Toolbar extends StatefulWidget {
  final Widget icon;
  final Widget rightIcon;
  final String title; //标题

  final Color toolbarBgColor; //toolbar背景色
  final Function backIconPress; //toolbar 左边点击事件
  final Function rightIconPress; //toolbar 右边点击事件
  final double titleSize; //标题字体大小
  final double toolbarHeight; //toolbar高度
  final Color titleColor;
  final Color statusBgColor;
  final bool rightIconShow; //显示右侧按钮

  Toolbar({
    Key key,
    this.backIconPress,
    this.rightIconPress,
    this.title = "",
    this.titleSize = 20,
    this.toolbarHeight = 50,
    this.toolbarBgColor = Colors.white,
    this.statusBgColor = Colors.white,
    this.titleColor = Colors.black,
    this.icon = const Icon(Icons.arrow_back_rounded),
    this.rightIcon,
    this.rightIconShow = false,
  }) : super(key: key);

  @override
  _ToolbarState createState() => _ToolbarState();
}

class _ToolbarState extends State<Toolbar> {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(color: widget.statusBgColor),
      child: Padding(
        padding:
            EdgeInsets.only(top: MediaQueryData.fromWindow(window).padding.top),
        child: Container(
          height: widget.toolbarHeight,
          decoration: BoxDecoration(color: widget.toolbarBgColor),
          child: Stack(
            children: [
              Align(
                  alignment: Alignment.centerLeft,
                  child: IconButton(
                      icon: widget.icon,
                      iconSize: 24.w,
                      onPressed: widget.backIconPress)),
              widget.rightIconShow
                  ? Align(
                      alignment: Alignment.centerRight,
                      child: IconButton(
                          iconSize: 44.w,
                          icon: widget.rightIcon,
                          onPressed: widget.rightIconPress),
                    )
                  : SizedBox(),
              Align(
                alignment: Alignment.center,
                child: Text(
                  widget.title,
                  style: TextStyle(
                    fontSize: widget.titleSize,
                    color: widget.titleColor,
                  ),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}
